package com.mszlu.msauth.admin.controller;

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.util.Date;
import java.util.Objects;

@Table(name = "ms_organization")
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@EntityListeners(value = AuditingEntityListener.class)
public class Organization {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;
    @Column(name = "name", nullable = false)
    @Comment("组织名称")
    private String name;
    @Column(name = "code", nullable = false)
    @Comment("组织代码")
    private String code;
    @Column(name = "parent_id", nullable = false)
    @Comment("上级ID")
    private Long parentId;
    @Column(name = "sort", nullable = false)
    @Comment("排序")
    private Long sort;
    @Column(name = "status", nullable = false)
    @Comment("状态 1 正常 0 禁用")
    private Integer status;
    @CreatedDate
    private Date createTime;
    @LastModifiedDate
    private Date updateTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
            return false;
        }
        Organization that = (Organization) o;
        return id != null && Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}